package net.pantolomin.nayo.api;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;

/**
 * Represents a connection to a remote host
 */
public interface Connection {
	/**
	 * @return the local address
	 * @throws ClosedChannelException
	 *           if the underlying channel is closed
	 * @throws IOException
	 *           if an I/O error occurred
	 */
	InetSocketAddress getLocalAddress() throws IOException;

	/**
	 * @return the remote host's address
	 * @throws ClosedChannelException
	 *           if the underlying channel is closed
	 * @throws IOException
	 *           if an I/O error occurred
	 */
	InetSocketAddress getRemoteAddress() throws IOException;

	/**
	 * @return true if the connection is closed
	 */
	boolean isConnected();

	/**
	 * Send some data to the remote host
	 * 
	 * @param data
	 *          the data to send
	 * @throws IOException
	 *           if an error occurred
	 */
	void send(ByteBuffer data) throws IOException;

	/**
	 * Close the connection
	 */
	void close();
}